package com.kpmg.datalake.common.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kpmg.datalake.common.dao.ComLangMpngMapper;
import com.kpmg.datalake.common.model.ComLangMpng;
import com.kpmg.datalake.common.service.IComLangMpngService;
import com.kpmg.datalake.common.utils.ContextHolderUtils;
import org.springframework.aop.framework.AopContext;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 国际化多语言配置表 服务实现类
 * </p>
 *
 * @author alex [alex.zhao@kpmg.com]
 * @since 2018-07-30
 */
@Service
public class ComLangMpngServiceImpl extends ServiceImpl<ComLangMpngMapper, ComLangMpng> implements
    IComLangMpngService {

  @Override
  public String getMultilingualByCode(String multiCode) {
    //为了走cache 通过代理对象访问
    return ((ComLangMpngServiceImpl) AopContext.currentProxy())
        .getMultilingualByCodeAndLang(multiCode, ContextHolderUtils.getLocale().toString());
  }

  @Override
  @Cacheable(value = "multilingual", key = "#multiCode+':'+#langCode", unless = "#result == null")
  public String getMultilingualByCodeAndLang(String multiCode, String langCode) {
    return baseMapper.getMultilingualByCodeAndLang(multiCode, langCode.toLowerCase());
  }
}
